package autocode

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
    "github.com/flipped-aurora/gin-vue-admin/server/model/autocode"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
    autocodeReq "github.com/flipped-aurora/gin-vue-admin/server/model/autocode/request"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
    "github.com/flipped-aurora/gin-vue-admin/server/service"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
)

type ActivityInfoApi struct {
}

var activityInfoService = service.ServiceGroupApp.AutoCodeServiceGroup.ActivityInfoService


// CreateActivityInfo 创建ActivityInfo
// @Tags ActivityInfo
// @Summary 创建ActivityInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body autocode.ActivityInfo true "创建ActivityInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /activityInfo/createActivityInfo [post]
func (activityInfoApi *ActivityInfoApi) CreateActivityInfo(c *gin.Context) {
	var activityInfo autocode.ActivityInfo
	_ = c.ShouldBindJSON(&activityInfo)
	if err := activityInfoService.CreateActivityInfo(activityInfo); err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeleteActivityInfo 删除ActivityInfo
// @Tags ActivityInfo
// @Summary 删除ActivityInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body autocode.ActivityInfo true "删除ActivityInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /activityInfo/deleteActivityInfo [delete]
func (activityInfoApi *ActivityInfoApi) DeleteActivityInfo(c *gin.Context) {
	var activityInfo autocode.ActivityInfo
	_ = c.ShouldBindJSON(&activityInfo)
	if err := activityInfoService.DeleteActivityInfo(activityInfo); err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteActivityInfoByIds 批量删除ActivityInfo
// @Tags ActivityInfo
// @Summary 批量删除ActivityInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除ActivityInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /activityInfo/deleteActivityInfoByIds [delete]
func (activityInfoApi *ActivityInfoApi) DeleteActivityInfoByIds(c *gin.Context) {
	var IDS request.IdsReq
    _ = c.ShouldBindJSON(&IDS)
	if err := activityInfoService.DeleteActivityInfoByIds(IDS); err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// UpdateActivityInfo 更新ActivityInfo
// @Tags ActivityInfo
// @Summary 更新ActivityInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body autocode.ActivityInfo true "更新ActivityInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /activityInfo/updateActivityInfo [put]
func (activityInfoApi *ActivityInfoApi) UpdateActivityInfo(c *gin.Context) {
	var activityInfo autocode.ActivityInfo
	_ = c.ShouldBindJSON(&activityInfo)
	if err := activityInfoService.UpdateActivityInfo(activityInfo); err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindActivityInfo 用id查询ActivityInfo
// @Tags ActivityInfo
// @Summary 用id查询ActivityInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query autocode.ActivityInfo true "用id查询ActivityInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /activityInfo/findActivityInfo [get]
func (activityInfoApi *ActivityInfoApi) FindActivityInfo(c *gin.Context) {
	var activityInfo autocode.ActivityInfo
	_ = c.ShouldBindQuery(&activityInfo)
	if err, reactivityInfo := activityInfoService.GetActivityInfo(activityInfo.ID); err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"reactivityInfo": reactivityInfo}, c)
	}
}

// GetActivityInfoList 分页获取ActivityInfo列表
// @Tags ActivityInfo
// @Summary 分页获取ActivityInfo列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query autocodeReq.ActivityInfoSearch true "分页获取ActivityInfo列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /activityInfo/getActivityInfoList [get]
func (activityInfoApi *ActivityInfoApi) GetActivityInfoList(c *gin.Context) {
	var pageInfo autocodeReq.ActivityInfoSearch
	_ = c.ShouldBindQuery(&pageInfo)
	if err, list, total := activityInfoService.GetActivityInfoInfoList(pageInfo); err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败", c)
    } else {
        response.OkWithDetailed(response.PageResult{
            List:     list,
            Total:    total,
            Page:     pageInfo.Page,
            PageSize: pageInfo.PageSize,
        }, "获取成功", c)
    }
}
